package com.ihm.labyrinth;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.preference.RingtonePreference;
import android.text.TextUtils;
import android.util.Log;

import java.util.List;
import java.util.Set;

/**
 * A {@link PreferenceActivity} that presents a set of application settings. On
 * handset devices, settings are presented as a single list. On tablets,
 * settings are split by category, with category headers shown to the left of
 * the list of settings.
 * <p>
 * See <a href="http://developer.android.com/design/patterns/settings.html">
 * Android Design: Settings</a> for design guidelines and the <a
 * href="http://developer.android.com/guide/topics/ui/settings.html">Settings
 * API Guide</a> for more information on developing a Settings UI.
 */
public class SettingsActivity extends PreferenceActivity {
	/**
	 * Determines whether to always show the simplified settings UI, where
	 * settings are presented in a single list. When false, settings are shown
	 * as a master/detail two-pane view on tablets. When true, a single pane is
	 * shown on tablets.
	 */
	private static final boolean ALWAYS_SIMPLE_PREFS = false;
	
	public static final String KEY_DISPLAY = "display";
	public static final String KEY_FPS = "fps";
	public static final String KEY_ACTUAL_LEVEL = "actualLevel";
	public static final String KEY_MAX_LEVEL = "maxLevel";
	public static final String KEY_LEVELS = "levels";
	public static final String KEY_LEVEL = "level";
	public static final String KEY_VIBRATION = "vibration";

	@Override
	protected void onPostCreate(Bundle savedInstanceState) {
		super.onPostCreate(savedInstanceState);
		
		addPreferencesFromResource(R.xml.preferences);
		
		Bundle bundle = getIntent().getExtras();
		Bundle level = bundle.getBundle(KEY_LEVELS);
		Bundle actualLevel = bundle.getBundle(KEY_ACTUAL_LEVEL);
		ListPreference listPreference = (ListPreference) findPreference("level");
		
		if (listPreference != null) {
		    CharSequence entries[] = new String[level.size()];
		    CharSequence entryValues[] = new String[level.size()];
		    Set<String> keySet = level.keySet();
		    int i = level.size()-1;
		    for (String key : keySet) {
		    	 Log.d("HELLO", "Entry : " + level.getString(key) + " - entryValues " + key);
			        entries[i] = level.getString(key);
			        entryValues[i] = key;
			        i--;
		    }
		    listPreference.setEntries(entries);
		    listPreference.setEntryValues(entryValues);
		    Log.d("HELLO", "Value : " + actualLevel.getString(SettingsActivity.KEY_ACTUAL_LEVEL));
		    listPreference.setValue(actualLevel.getString(SettingsActivity.KEY_ACTUAL_LEVEL));
		}
		else{
			Log.d("HELLO", "No listPreference");
		}
		
	}

	
}
